package com.jack.leetcode.eachProblem2022;

public class _1629 {

    public static char slowestKey(int[] releaseTimes, String keysPressed) {
        int n = releaseTimes.length;
        int[] lastTime = new int[n];

        lastTime[0] = releaseTimes[0];
        int max = lastTime[0];
        for(int i = 1;i < n;i++){
            lastTime[i] = releaseTimes[i] - releaseTimes[i - 1];
            if(max < lastTime[i]){
                max = lastTime[i];
            }
        }

        char result = 'a';
        for(int i = 0;i < n;i++){
            if(max == lastTime[i]){
                result = (char)Math.max((int)result, (int)keysPressed.charAt(i));
            }
        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(slowestKey(new int[]{12,23,36,46,62}, "spuda"));
        System.out.println(slowestKey(new int[]{9,29,49,50}, "cbcd"));
    }
}
